#!/bin/bash

progress_bar_0()
{
    i=0
    bar=''
    index=0
    arr=( "|" "/" "-" "\\" )
    while [ $i -le 100 ]
    do
        let index=index%4
        printf "[%-100s][%d%%][\e[43;46;1m%c\e[0m]\r" "$bar" "$i" "${arr[$index]}"
        let i++
        let index++
        sleep 0.01
        bar+='#'
    done
    printf "\n"
}

progress_bar_1()
{
    b=''
    for ((i=0;$i<=100;i+=2))
    do
        printf "[%-50s]%d%%\r" $b $i
        sleep 0.01
        b=#$b
    done
    echo
}

progress_bar_2()
{ 
    num=0
    str='#'
    max=100
    pro=('|' '/' '-' '\')
    while [ $num -le $max ]
    do
        ((color=30+num%8))
        echo -en "\e[1;"$color"m"
        let index=num%4
        printf "[%-100s %d%% %c]\r" "$str" "$num" "${pro[$index]}"
        let num++
        sleep 0.01
        str+='#'
    done
    # printf "\n"
    echo -e "\e[1;30;m"
}

progress_bar_3()
{
    local current=$1; local total=$2
    local now=$((current*100/total))
    local last=$(((current-1)*100/total))
    [[ $((last % 2)) -eq 1 ]]&&let last++
    local str=$(for i in `seq 1 $((last/2))`; 
    do 
        printf '#'; done)

    for ((i=$last;$i<=$now;i+=2));
        do 
            printf "\r[%-50s]%d%%" "$str"  $i;
            sleep 0.01;
            str+='#';
        done
}

echo "progress_bar_0"
progress_bar_0

echo "progress_bar_1"
progress_bar_1

echo "progress_bar_2"
progress_bar_2

echo "progress_bar_3"
for  n in `seq 1 100`
    do
        progress_bar_3 $n 100
    done
echo

# end
